package com.example.xd.javatest;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.nfc.Tag;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import com.example.xd.javatest.activity_task_test.SecondActivity;
import com.example.xd.javatest.lambda.Add;
import com.example.xd.javatest.okhttp_test.OkhttpTest;
import com.example.xd.javatest.retrofit_test.NetApi;
import com.example.xd.javatest.retrofit_test.RetrofitTest;
import com.example.xd.javatest.retrofit_test.bean.Bean;
import com.example.xd.javatest.retrofit_test.RetrofitClient;
import com.example.xd.javatest.rxjava_test.RxJavaTest;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
    public static String TAG = "xd---";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        findViewById(R.id.btn_rxjava).setOnClickListener(this);
        findViewById(R.id.btn_retrofit).setOnClickListener(this);
        findViewById(R.id.btn_task).setOnClickListener(this);
        findViewById(R.id.btn_okhttp).setOnClickListener(this);
        findViewById(R.id.btn_lambda).setOnClickListener(this);
        Log.i("xd----", "MainActivity-----taskId===" + getTaskId());

        Button btn_test = findViewById(R.id.btn_test);
//        btn_test.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                Log.i(TAG, "onCreate: ");
//            }
//        });

        Add add = new Add() {
            @Override
            public int add(int a, int b) {
                return a + b;
            }
        };

        Add lambda_add = (a, b) -> a + b;
        btn_test.setOnClickListener(v -> Log.i(TAG, "onCreate: " + lambda_add.add(4, 2)));

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_rxjava:
                RxJavaTest.test7();
                break;
            case R.id.btn_retrofit:
                retrofit_test();
                break;
            case R.id.btn_task:
                startActivity(new Intent(MainActivity.this, SecondActivity.class));
                break;
            case R.id.btn_okhttp:
                OkhttpTest.test_get();
                break;
            case R.id.btn_lambda:
                lambda_test();
                break;
        }
    }

    private void lambda_test() {
        Runnable runnable = new Runnable() {
            @Override
            public void run() {
                Log.i(TAG, "run: ");
            }
        };
        new Thread(runnable).start();


        Runnable lambda_run = () -> Log.i(TAG, "lambda_test: ");
        new Thread(lambda_run).start();

    }

    private void retrofit_test() {
        RetrofitTest.getData1();

    }
}
